package com.waves.search.controller;

/**
 * @author Eden
 * @date 2024/10/14 21:35
 **/

import com.waves.core.web.domain.TableDataInfo;
import com.waves.search.dto.EsSearchDTO;
import com.waves.search.enums.SearchTypeEnums;
import com.waves.search.service.task.TaskSearchService;
import com.waves.search.service.user.UserSearchService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;


@RestController
@RequestMapping("/search")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@ApiModel("es搜索")
public class SearchController {

    private final TaskSearchService taskSearchService;

    private final UserSearchService userSearchService;

    @ApiOperation("获取es搜索")
    @GetMapping("/page")
    @ApiResponses(@ApiResponse(code = 200, message = "success"))
    public TableDataInfo page(EsSearchDTO esSearchDTO) {
        Integer type = esSearchDTO.getType();
        if (Objects.equals(type, SearchTypeEnums.USER.getCode())) {
            return userSearchService.pageTask(esSearchDTO);
        } else if (Objects.equals(type, SearchTypeEnums.TASK.getCode())) {
            return taskSearchService.pageTask(esSearchDTO);
        }
        return null;
    }


}
